package com.srt;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.StringTokenizer;

public class InputQuery {
	private final static String LOCAL_URL = "jdbc:oracle:thin:@localhost:1521:xe";
	private final static String DOMAIN_URL = "jdbc:oracle:thin:@172.24.4.180:1521:orcl";
	private final static String LOCAL_PASSWORD = "password";
	private final static String LOCAL_NAME = "admin";
	private final static String DOMAIN_PASSWORD = "tr00per";
	private final static String DOMAIN_NAME = "test";

	// New Method parse string before enter to data

	public static void toData(String firstTen) {
		String pare, count, word, ss;
		StringTokenizer tokenizer = new StringTokenizer(firstTen, " ;");
		StringTokenizer tok;
		while (tokenizer.hasMoreElements()) {
			pare = (String) tokenizer.nextElement();
			tok = new StringTokenizer(pare, "-");
			while (tok.hasMoreElements()) {
				count = (String) tok.nextElement();
				word = (String) tok.nextElement();
				ss = "INSERT INTO TEST.FIRST10 (COUNT,WORD) VALUES ('"
						+ count.toString() + "', '" + word.toString() + "')";
				inputToData(ss);

			}
		}
	}

	private static void inputToData(String sql) {
		try {
			Properties props = new Properties();
			props.setProperty("user", LOCAL_NAME);
			props.setProperty("password", LOCAL_PASSWORD);
			// creating connection to Oracle database using JDBC
			Connection conn = DriverManager.getConnection(LOCAL_URL, props);
			PreparedStatement preStatement = conn.prepareStatement(sql);
			ResultSet result = preStatement.executeQuery();
			System.out.println("done " + result.toString());

		} catch (Exception e) {
			System.out.println(e);

		}
	}

}
